function [ equityend, sharpe, annually_compound_return] = TestPerformance( position, close, onewaycost )
%TESTPERFORMANCE Summary of this function goes here
%   Detailed explanation goes here
%profit and loss(pnl)
N = length(close);
dailyret = zeros(1,N);
dailyret(2:N) = (close(2:N)-close(1:N-1))./close(1:N-1); % daily returns

dailypnl = position(1:N).*dailyret;
dailypnlminustcost = dailypnl;

dailypnlminustcost(2:N) = dailypnl(2:N) - abs...
     (position(2:N)-position(1:N-1)).*onewaycost;
% sharpeminustcost=sqrt(250)*mean...
%     (dailypnlminustcost(2:end,:))./std(dailypnlminustcost(2:end,:));
sharpe = sqrt(250)*mean...
     (dailypnlminustcost(2:end))/std(dailypnlminustcost(2:end));
%Reconstruct Equity portfolio
equity = zeros(1,N);
equity(1) = 1;
for i = 2:N
    equity(i) = equity(i-1)*(1+dailypnlminustcost(i));    
end
equityend = equity(end);
annually_compound_return = exp(log(equity...
    (end)/equity(1))/(length(position)/250))-1;
end

